<!DOCTYPE html>
<script src="../../../resources/js-test.js"></script>
<style>
.c5 > .c4 ~ .c3 .c2 + .c1 { background-color: green }
</style>
<!--
Expected sets

.c1 { }
.c2 + { .c1 }
.c3 { .c1 }
.c4 ~ { .c3 } { .c1 }
.c5 { .c1 }

-->
<div id="i5">
    <div id="i4"></div>
    <div></div>
    <div></div>
    <div></div>
    <div id="i3">
        <div>
            <div id="i2"></div>
            <div id="i1">
                <div>This text should have a green background.</div>
                <span></span>
                <span></span>
            </div>
        </div>
    </div>
</div>
<script>
description("Check that targeted class invalidation works with when adjacent combinators are present.");

var transparent = "rgba(0, 0, 0, 0)";
var green = "rgb(0, 128, 0)";

var i1 = document.getElementById("i1");
var i2 = document.getElementById("i2");
var i3 = document.getElementById("i3");
var i4 = document.getElementById("i4");
var i5 = document.getElementById("i5");

shouldBe("getComputedStyle(i1, null).backgroundColor", "transparent");

document.body.offsetTop; // Force style recalc.
i1.className = "c1";
if (window.internals)
    shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "1");

document.body.offsetTop; // Force style recalc.
i2.className = "c2";
if (window.internals)
    shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "1");

document.body.offsetTop; // Force style recalc.
i3.className = "c3";
if (window.internals)
    shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "1");

document.body.offsetTop; // Force style recalc.
i4.className = "c4";
if (window.internals)
    shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "1");

shouldBe("getComputedStyle(i1, null).backgroundColor", "transparent");

document.body.offsetLeft; // force style recalc.
i5.className = "c5";
if (window.internals)
    shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "1");

shouldBe("getComputedStyle(i1, null).backgroundColor", "green");

</script>
